
/**
 * @description 根据key将数组对象进行排序
 * @param {Array} arr 源数据
 * @param {String|Number}key  排序字段/排序规则
 * @param {Number}type  排序规则
 * @returns {Array}arr 
 */
const sortBy = function (arr: any[], key = 1, type = 1) {
	const length = arguments.length;
	function fn (a: any, b: any) {
		if (length > 2) {
			if (type === 1) return a[key] - b[key];//升序
			else return b[key] - a[key];//降序
		} else {
			if (key === 1) return a - b;//升序
			else return b - a;//降序
		}
	}
	arr.sort(fn);
	return arr;
};
export default sortBy;